package main

import (
	"fmt"
	"time"
)

func main() {
	// 带有缓存的channel
	c := make(chan int, 3)
	fmt.Println("len(c) = ", len(c), "cap(c) = ", cap(c))

	go func() {
		defer fmt.Println("goroutine结束...")
		for i := 0; i < 3; i++ {
			c <- i
			fmt.Println("goroutine协程，正在发送数据：", i, "len(c) = ", len(c), "cap(c) =", cap(c))
		}
	}()

	time.Sleep(2 * time.Second)

	for i := 0; i < 3; i++ {
		num := <-c
		fmt.Println("读取到的数据 num = ", num)
	}
	fmt.Println("main结束...")
}
